package com.baidu.tcpChatDemo2;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

public class ChatClient {
    public static void main(String[] args) throws Exception {
        Socket socket = new Socket("127.0.0.1", 9191);

        //主线程负责创建socket发送消息 子线程负责接收客户端发送过来的消息
        ChatClientReaderThread chatClientReaderThread = new ChatClientReaderThread(socket);
        chatClientReaderThread.start();

        //主线程发送消息
        Scanner scanner = new Scanner(System.in);
        while (true){
            String next = scanner.next();
            OutputStream outputStream = socket.getOutputStream();
            PrintStream printStream = new PrintStream(outputStream);

            printStream.println(next);
            printStream.flush();
        }
    }
}
